<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VUE3</title>
  </head>
  <body>
    <div id="app"></div>

    <template id="tpl">
      <div>
        <input v-model="msg" />
      </div>
      <div>{{ result }}</div>
    </template>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      Vue.createApp({
        template: "#tpl",
        data() {
          return {
            msg: "",
            result: "",
          };
        },
        watch: {
          msg(newVal, oldVal) {
            console.log(newVal, oldVal);
            if (!newVal) {
              this.result = "";
              return;
            }
            this.result = `*${newVal}*`;
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
